<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="./button.css">
    <style>
        body {
            background-image: url(../login_picture/background.jpg);
        }

        * {
            margin: 0;
            height: 0;
            box-sizing: border-box;
        }

        .log_tips {
            width: 100%;
            height: 100px;
        }

        .login_wrap {
            width: 100%;
            height: 500px;
            margin-top: 120px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .link {
            width: 100%;
            height: 100px;

        }

        #login {
            width: 400px;
            height: 340px;
            background-color: rgb(38, 93, 125);
            opacity: 0.7;
            border-radius: 10px;

        }

        form {
            margin: 30px 0;
            width: 100%;
            height: 240px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-evenly;
            /* background-color: black; */
        }

        form>input {
            padding: 9px 10px;
            width: 300px;
            height: 34px;
            border-radius: 5px;
            opacity: 0.5;
        }

        form>button {
            width: 200px;
            height: 38px;
            border-radius: 50px;
            /* background-color: coral; */
            background: linear-gradient(280deg, rgb(240, 11, 11), rgb(247, 14, 14));
            color: #fff;
            outline: none;
        }

        .login_links {

            text-align: center;
        }

        .login_links a {
            text-decoration: none;
            color: #fff;
            display: inline-block;
            width: 120px;
            height: 30px;

        }
    </style>
</head>

<body>
    <div class="login_wrap">
        <div id="login">
            <form action="">
                <input type="text" placeholder="请输入账号">
                <input type="password" placeholder="请输入密码">
                <input type="password" placeholder="请确认密码">
                <input type="text" placeholder="输入手机号">
                <a href="javascript:;" class="aki-btn">
                    <span>注&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;册</span>
                </a>
            </form>
            <div class="login_links">
                <a href="./login.html" target="_blank">以有账号?去登录</a>
            </div>
        </div>
    </div>
    <div class="link"></div>
</body>
<script>
    let ipts = document.querySelectorAll('form input')
    let btn = document.querySelector('.aki-btn')
    let regUser = /^[a-zA-Z]\w{4,15}$/
    let regPass = /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]/
    let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/
    ipts[0].addEventListener('blur', function () {
        let username = ipts[0].value
        if (!regUser.test(username)) {
            ipts[0].value = '名字不合法!请输入4-15位英文加数字组合'
            ipts[0].style.color = 'red'
            setTimeout(function () {
                ipts[0].value = username
                ipts[0].style.color = 'black'
            }, 2000)
        }
    })
    ipts[3].addEventListener('blur', function () {
        let phone = ipts[3].value
        if (!regPhone.test(phone)) {
            ipts[3].value = '手机号无效!'
            ipts[3].style.color = 'red'
            setTimeout(function () {
                ipts[3].value = phone
                ipts[3].style.color = 'black'
            }, 2000)
        }
    })
    btn.addEventListener('click', function () {
        let username = ipts[0].value
        let password = ipts[1].value
        let passwordAgain = ipts[2].value
        let phone = ipts[3].value
        if (password !== passwordAgain&& password!=="密码不能为空!"&&passwordAgain!=="验证密码不能为空!") {
            ipts[2].type="text"
            ipts[2].value = '两次密码不匹配,请重新输入!'
            ipts[2].style.color = 'red'
            ipts[1].type="text"
            ipts[1].value = '两次密码不匹配,请重新输入!'
            ipts[1].style.color = 'red'
            setTimeout(function () {
                ipts[2].type = "password"
                ipts[2].value = ""
                ipts[2].style.color = 'black'
                ipts[1].type = "password"
                ipts[1].value = ""
                ipts[1].style.color = 'black'
            }, 2000)
        }
        if (username==="") {
            ipts[0].value="用户名不能为空!"
            ipts[0].style.color = 'red'
             setTimeout(function () {
                ipts[0].value = phone
                ipts[0].style.color = 'black'
            }, 2000)
        }
        if (phone==="") {
            ipts[3].value="手机号不能为空!"
            ipts[3].style.color = 'red'
             setTimeout(function () {
                ipts[3].value = phone
                ipts[3].style.color = 'black'
            }, 2000)
        }
        if (password==="") {
            ipts[1].type = "text"
            ipts[1].value="密码不能为空!"
            ipts[1].style.color = 'red'
             setTimeout(function () {   
                ipts[1].style.color = 'black'
                ipts[1].value = ""
                ipts[1].type = "password"
            }, 2000)
        }
        if (passwordAgain==="") {
            ipts[2].type = "text"
            ipts[2].value="验证密码不能为空!"
            ipts[2].style.color = 'red'
             setTimeout(function () {               
                ipts[2].style.color = 'black'
                ipts[2].value = ""
                ipts[2].type = "password"
            }, 2000)
        }
    })
</script>

</html>